Working with Global Variables
All .NET types in these namespaces can be used as global variables.
Variables can be declared in the script itself, but their values will be reinitialized when subsequent rows are executed. The Variables tab can be used to declare variables that will retain their values through all row executions. The initial values or instantiation of these variables should always be done when a script variable “FirstExecute” is set to a Boolean ‘true’. A default script is shown when the operation is started up. This gives an example of how to use the FirstExecute property.
Initializing global variables (globals)
Globals must always be initialized before they are accessed. As a “best practice” this is typically done in a “FirstExecute” block at the top of your script. In initializing globals in a First Execute block, we can be ensured that memory allocation is done only once for the variables.
On subsequent executes of the script, the values of these variables are persisted.
Example:
VB: |
if (FirstExecute) { // Initialize a row counter and the custom Field<T> type myStateField = new Field<double>(12.5); rowCounter = 1; } // Increase the number of the execution row on all executes ++rowCounter; |
Related topics: